package 结构型模式.桥接模式;

/**
 * @ClassNameBridgeTest
 * @Description
 * @Author
 * @Date2021/12/15 17:42
 **/
public class BridgeTest {
    public static void main(String[] args) {
        // 新建黄色的吉普车
        JeepCar jeepCar = new JeepCar();
        jeepCar.setCar(new Yellow());
        System.out.println(jeepCar.getName());


        // 新建红色的吉普车
        SuvCar suvCar = new SuvCar();
        suvCar.setCar(new RedColor());
        System.out.println(suvCar.getName());
    }
}

interface Color {
    String getColor();
}


interface Car {
    void setCar(Color color);

    String getName();
}

class SuvCar implements Car {
    private Color color;

    @Override
    public void setCar(Color color) {
        this.color = color;
    }

    @Override
    public String getName() {
        return "这是" + color.getColor() + "的" + "suv";
    }
}


class JeepCar implements Car {

    private Color color;

    @Override
    public void setCar(Color color) {
        this.color = color;
    }

    @Override
    public String getName() {
        return "这是" + color.getColor() + "的" + "吉普车";
    }
}


class RedColor implements Color {

    @Override
    public String getColor() {
        return "红色";
    }
}

class Yellow implements Color {

    @Override
    public String getColor() {
        return "黄色";
    }
}

